package com.itheima;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main(String[] args) {
        Map<String,String> data  = new HashMap<>();
        data.put("小王","A");
        data.put("小李","B");
        data.put("小张","C");
        data.put("小赵","D");
        data.put("小钱","A");
        data.put("小孙","B");
        data.put("小王2","C");
        data.put("小李2","A");
        data.put("小李3","B");
        data.put("小李4","C");
        data.put("小李5","D");
        data.put("小王6","C");
        data.put("小王7","A");
        data.put("小李8","B");
        data.put("小李9","C");
        data.put("小李10","D");
        data.put("小王11","C");
        data.put("小李12","A");
        data.put("小李13","B");
        data.put("小李14","C");
        data.put("小李15","D");
        data.put("小王16","C");
        //调用方法统计
        count(data);
    }

    public static void count(Map<String,String> data){

        Map<String,Integer> resultMap  = new HashMap<>();
        data.forEach((k,v)->{
            boolean containsKey = resultMap.containsKey(v);
            if (containsKey){

                Integer oldCount = resultMap.get(v);
                resultMap.put(v,oldCount+1);
            }else {//不存在
                resultMap.put(v,1);
            }
        });
        //6. 遍历新map集合，打印结果
        resultMap.forEach((k,v)->{
            System.out.println(k+"-->"+v);
        });
    }

}

